<?php

session_start();
include ('Users.php');
include ('sqlconnection.php');
if($_POST['username'] != '' && $_POST['password'] != '' && $_POST['email'] !=''){
	$username = $_POST['username'];
	$password = $_POST['password'];
	$email = $_POST['email'];
	
	$user = new Users($username, $password, $email);
	
	
	$_SESSION['user'] = $user;
	
	$db = new Database();
	$db->connect();
	$query = "select * from usertable where username = '$user->username'";
	$result = mysql_query($query);
	
	if(mysql_num_rows($result) > 0){
		echo "0";	
	}else{
		
		$query = "insert into usertable (username, email, password, firsttime) values ('$username', '$email', '$password', 1)";
		
		$result = mysql_query($query);
		$count = mysql_affected_rows();
		
		$db->disconnect();
		
		if($count == 1){
			echo "1";
		}else{
			echo "0";
		}
	}
}else
	print "0";
	


?>